package com.javashow.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.javashow.pojo.Log;
import com.javashow.pojo.Person;
import com.javashow.service.ITestService;
 
@Controller
public class TestController {
	
	@Autowired
	private ITestService testService;
	
	@RequestMapping("/test")
	public ModelAndView helloWord(Model model){
		
		String resultJsp = "result";
		String message = "Hello World, Spring 3.0!";
		ModelAndView mav = new ModelAndView(resultJsp);
		mav.addObject("test", "test");
		mav.addObject("message", message);
		mav.setViewName(resultJsp);
		Person person = new Person();
		person.setName("任志文");
		person.setAge(23);
		person.setBirthday(new Date());
		Log log = new Log();
		log.setContent("新增人员");
		log.setLog_time(new Date());
		testService.insertPerson(person, log);
		//testService.test();
		return mav;
		
		//return new ModelAndView("result", "message", message);
	}
	
	//@RequestMapping(value = "/test", method = RequestMethod.GET)
	/*public String helloWord(Model model){
		System.out.println("--------");
		String message = "Hello World, Spring 3.0!";
		model.addAttribute("message", message);
		return "result";
	}*/
	/*public ModelAndView helloWord(){
		System.out.println("------------------------------");
		String message = "Hello World, Spring 3.0!";
		return new ModelAndView("result", "message",message);
	}*/

	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		// TODO Auto-generated method stub
		String aMessage = "Hello World MVC!";
		System.out.println("******************");
		ModelAndView modelAndView = new ModelAndView("hello_world");
		modelAndView.addObject("result", aMessage);
 
		return modelAndView;
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public ModelAndView login(HttpServletRequest request) {
		ModelAndView result = new ModelAndView();
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println(username + "      " + password);
		
		return result;
	}
}
